<?php
add_shortcode( 'tm_timespec', 'tm_specific_times' );
function tm_specific_times($att){
	if ( ! function_exists( 'jdate' ) ) {
		date_default_timezone_set( 'Asia/Tehran' );
		include( tiremanager_plugin_dir_path . 'lib/jdf.php' );
	}
	if(!function_exists("is_tatil")) {
		require( tiremanager_plugin_dir_path . 'index.php' );
	}

	$att = shortcode_atts([
		"gid"=>6,
		"start"=>"10:00",
		"end"=>"13:00",
		"msg"=>"
ثبت نام هم اکنون فعال نمی باشد
		",
		"holidays"=>true
	],$att);
//	err_log($att);
	$now = time();
	$now_h =(int) date("G",$now);
	$now_m = (int)date("i",$now);
	$now_m_all = $now_h * 60 + $now_m;
	$start_h = (int) explode(":",$att['start'])[0];
	$start_m =(int)  explode(":",$att['start'])[1];
	$start = $start_h * 60 + $start_m;
	$end_h = (int) explode(":",$att['end'])[0];
	$end_m = (int) explode(":",$att['end'])[1];
	$end = $end_h*60 + $end_m;
	$checked_tatile = false;
	//err_log($start);
	//err_log($end);
	//err_log($now_m_all);
	if ($att["holidays"]=="false" ||$att["holidays"]=="0" ||  $att["holidays"]==0) $att['holidays']=false;
	if ($att["holidays"]){
		$jnow = jdate('Y-m-d',$now,false,false,'en');
		if (is_tatil($jnow)>5){
			$checked_tatile = true;
		}
	}
	if (
		($start <= $now_m_all && $now_m_all <= $end)
	&&
		(!$checked_tatile)
	){
		return(gravity_form($att['gid']));
	}
	else echo $att['msg'];

}
